package sbduoyi;

import java.util.Arrays;

/**
 * 一个长度位n的数组向右移动k位
 * 先把0到k-1翻转
 * 再把k-1翻转
 * 最后整合数组翻转
 */
public class ShuzuYidong {
    public static void main(String[] args) {
        int arr[] = {1,2,3,4,5,6,7};
        int k = 3;
        reserve(arr,0,k-1);
        reserve(arr,k,arr.length-1);
        reserve(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
    public static void reserve(int arr[],int left,int right){
        for(int i=left,j=right;i<=j;){
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] =temp;
            i++;
            j--;
        }
    }
}
